public class Solution {
    public static int StrToInt(String str) {
        int sum = 0;
        if(str.isEmpty()) return 0;
        for (int i  = 0; i < str.length(); i++) {
            char ch = str.charAt(i);
            if (ch >= '0' && ch <= '9') {
                sum = sum * 10 + str.charAt(i) - '0';
            } else if (ch == '+' || ch == '-') {
                //i++;
            } else {
                return 0;
            }
        }
        if (str.charAt(0) == '-') return -sum;
        return sum;
    }
}
